package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        try (
            Connection connection = DBUtil.getConnection()
        ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.salary,t.title,c.name,c.floor " +
                         "FROM teacher t " +
                         "JOIN class c ON c.teacher_id = t.id " +
                         "WHERE t.name='王克晶'";
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
//                String tName = resultSet.getString("t.name");
//                int tSalary = resultSet.getInt("t.salary");
//                String tTitle = resultSet.getString("t.title");
//                String cName = resultSet.getString("c.name");
//                int cFloor = resultSet.getInt("c.floor");
                String tName = resultSet.getString(1);
                int tSalary = resultSet.getInt(2);
                String tTitle = resultSet.getString(3);
                String cName = resultSet.getString(4);
                int cFloor = resultSet.getInt(5);
                System.out.println(tName+" "+tSalary+" "+tTitle+" "+cName+" "+cFloor);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
